package com.jumi.microservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jumi.microservice.domain.AccountRoleRelationship;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 账号和角色的关系表 Mapper 接口
 * </p>
 *
 * @author liuz
 * @since 2020-07-18
 */
public interface AccountRoleRelationshipMapper extends BaseMapper<AccountRoleRelationship> {

    /**
     * 根据账号查找所有的角色的名称
     *
     * @param accountId 账号
     * @return 账号
     */
    @Select("SELECT GROUP_CONCAT(role.role_name) name FROM auth_role role" +
            " INNER JOIN (SELECT account_id, role_id FROM auth_account_role_relationship WHERE account_id = #{accountId}) relationship" +
            " ON role.id = relationship.role_id AND role.STATUS = 1 AND role.is_del = 0 " +
            " ORDER BY role.order_num DESC,role.update_time DESC")
    String getRoleNameByAccountId(@Param("accountId") Long accountId);
}
